<?php

class DefaultRouteSvc extends BaseObject {
	public function slotRoute($path, &$final) {
		$parts = explode('/',$path);
		$r = array();
		$r['ctrl'] = @$parts[0];
		if(!$r['ctrl']) {$r['ctrl'] = 'Index'; }
		$r['act'] = @$parts[1];
		if(!$r['act']) {$r['act'] = 'Index'; }
		$final = true;
		return $r;
	}

	public function slotUrl(&$args, &$final) {
		$url = '';
		if($ctrl = @$args['ctrl']) {
			$url.=$ctrl;
			if($act = @$args['act']) {
				$url.='/'.$act;
			}
		}
		unset($args['ctrl']);
		unset($args['act']);
		if(count($args)) {
			$url.='?'.http_build_query($args);
		}
		
		return $url;
	}
	
	
	public function __construct() {
		$this->signal()->subscribe('route', array($this, 'slotRoute'), 1000000);
		$this->signal()->subscribe('url', array($this, 'slotUrl'), 1000000);
	}
}
